// https://www.shadertoy.com/view/MdXcR7  Simple Scanline

const ScanLineShader = {
  shaderID: 'ScanLineShader',

  uniforms: {
    'iTime': { value: 1.0 },
    'modelHeight': { value: 1.0 }, // 模型高度，约定模型的原点位于底部投影的中心
  },

  vertexShader: /* glsl */`
  varying float height;
  uniform float modelHeight;
  
  void main() {
    height = position.z + modelHeight * 0.5;
    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  }`,

  fragmentShader: /* glsl */`
	uniform float iTime;
  uniform float modelHeight;
  varying float height;
  
  void main() {
    float uvY = 1.0 - height / modelHeight;
    float y = mod(iTime, 1.9) - 0.4;
    float colorAdd = pow(1.2 - pow(abs(uvY - y), .3), 3.);
    gl_FragColor.g = colorAdd * .5;
    gl_FragColor.b = colorAdd * 1.;
    gl_FragColor.a = colorAdd * colorAdd;
  }
  
  void main2() {
    vec3 color = vec3(0.0, 0.5, 1.0);
    float val = 0.5 - height / modelHeight;
    float t = mod(iTime / 2.0, 1.0);
    
    float b = 1.0 - 2.0 * abs(t - val);
    float a = pow(b, 24.0);
    gl_FragColor = vec4(color * a * 1.414 , a);
  }
`
}

export default ScanLineShader;
